//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.come.good;

import com.tool.pet.BabyProperty;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.come.Frame.TestChildJframe;
import org.come.Frame.ZhuFrame;
import org.come.bean.BabyResult;
import org.come.entity.Baby;
import org.come.entity.Goodstable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;
import org.come.until.UserMessUntil;
import org.come.until.Util;

public class BabyGood {
	public BabyGood() {
	}

	public static void BabyGoods(Goodstable goodstable, long type) {
		Baby baby = UserMessUntil.getbaby(TestChildJframe.getTestChildJframe().getTestChildJpanel().getBabyid());
		if (baby == null) {
			ZhuFrame.getZhuJpanel().addPrompt2("你没有选中的孩子");
		} else {
			if (type == 50) {
				training(baby, goodstable);
			} else if (type == 51) {
				babySkill(baby, goodstable);
			} else if (type >= 54 && type <= 61) {
				babyParts(baby, goodstable);
			} else if (type == 53) {
				ageReturn(baby, goodstable);
			}

		}
	}

	public static void training(Baby baby, Goodstable goodstable) {
		String[] v = goodstable.getValue().split("\\|");
		v = v[Util.random.nextInt(v.length)].split("=");
		String k = v[0];
		v = v[1].split("-");
		int min = Integer.parseInt(v[0]);
		int max = Integer.parseInt(v[1]);
		int ch = max - min + 1;
		int value = Util.random.nextInt(ch) + min;
		if (value <= min + 1 || value >= max - 1) {
			value = Util.random.nextInt(ch) + min;
		}

		switch(k.hashCode()) {
			case 668086:
				if ("内力".equals(k)) {
					baby.setNeili(baby.getNeili() + value);
				}
				break;
			case 694695:
				if ("名气".equals(k)) {
					baby.setMingqi(baby.getMingqi() + value);
				}
				break;
			case 702347:
				if ("叛逆".equals(k)) {
					baby.setPanni(baby.getPanni() + value);
				}
				break;
			case 749574:
				if ("孝心".equals(k)) {
					baby.setXiaoxin(baby.getXiaoxin() + value);
				}
				break;
			case 834401:
				if ("智力".equals(k)) {
					baby.setZhili(baby.getZhili() + value);
				}
				break;
			case 893844:
				if ("气质".equals(k)) {
					baby.setQizhi(baby.getQizhi() + value);
				}
				break;
			case 942494:
				if ("玩性".equals(k)) {
					baby.setWanxing(baby.getWanxing() + value);
				}
				break;
			case 1037451:
				if ("耐力".equals(k)) {
					baby.setNaili(baby.getNaili() + value);
				}
				break;
			case 1169860:
				if ("道德".equals(k)) {
					baby.setDaode(baby.getDaode() + value);
				}
		}

		baby.setBabyage(baby.getBabyage() + 10);
		adult(baby);
		UpdaBaby(baby);
		if (FormsManagement.getframe(1).isVisible()) {
			TestChildJframe.getTestChildJframe().getTestChildJpanel().ShowBaby(baby);
		}

		String msg = "孩子在#G " + k + " #Y上增加了#G " + value + " #Y点属性";
		ZhuFrame.getZhuJpanel().addPrompt2(msg);
		goodstable.goodxh(1);
		GoodsMouslisten.gooduse(goodstable, 1);
	}

	public static void adult(Baby baby) {
		if (baby.getBabyage() >= 6480) {
			if (baby.getOutcome() == null || "".equals(baby.getOutcome())) {
				List<BabyResult> babyResults = UserMessUntil.getAllBabyResult().getAllBabyResults();
				Map<String, Integer> maps = BabyProperty.getBabyProperty().getProperty(baby, baby != null ? baby.getpartAll() : null);
				int size = 0;
				int max = 0;
				String maxtype = "";
				Iterator it = maps.keySet().iterator();

				while(it.hasNext()) {
					String key = (String)it.next();
					int value = (Integer)maps.get(key);
					size += value;
					if (value >= max) {
						max = value;
						maxtype = key;
					}
				}

				BabyResult babyResult = null;

				label63:
				for(int i = babyResults.size() - 1; i >= 0; --i) {
					babyResult = (BabyResult)babyResults.get(i);
					if ("无".equals(babyResult.getT1()) || babyResult.getT1().equals(maxtype)) {
						String[] t2s = babyResult.getT2().split("\\|");
						int j = 0;

						while(true) {
							if (j >= t2s.length) {
								break label63;
							}

							String[] vs = t2s[j].split("=");
							int value = size;
							if (!"总".equals(vs[0])) {
								value = (Integer)maps.get(vs[0]);
							}

							vs = vs[1].split("\\-");
							int bmin = Integer.parseInt(vs[0]);
							int bmax = Integer.parseInt(vs[1]);
							if (value < bmin || value > bmax) {
								break;
							}

							++j;
						}
					}
				}

				if (baby.getChildSex() == 0) {
					baby.setOutcome(babyResult.getNan());
				} else {
					baby.setOutcome(babyResult.getNv());
				}

				ZhuFrame.getZhuJpanel().addPrompt2("孩子获得#G" + baby.getOutcome() + "结局");
			}
		}
	}

	public static void ageReturn(Baby baby, Goodstable goodstable) {
		if (baby.getBabyage() < 360) {
			ZhuFrame.getZhuJpanel().addPrompt2("孩子太小不能使用");
		} else if (baby.getBabyage() >= 6480) {
			ZhuFrame.getZhuJpanel().addPrompt2("回不去了#15");
		} else {
			String[] v = goodstable.getValue().split("-");
			int min = Integer.parseInt(v[0]);
			int max = Integer.parseInt(v[1]);
			int ch = max - min + 1;
			int value = Util.random.nextInt(ch) + min;
			int[] vs = new int[]{baby.getQizhi(), baby.getNeili(), baby.getZhili(), baby.getNaili(), baby.getMingqi(), baby.getDaode(), baby.getPanni(), baby.getWanxing(), baby.getXiaoxin()};

			int j;
			for(int pin = value / 5; value > 0; value -= j) {
				int a = 0;

				for(j = 0; j < vs.length; ++j) {
					if (vs[j] <= 0) {
						++a;
					}
				}

				if (a >= 9) {
					break;
				}

				j = pin;
				if (pin > value) {
					j = value;
				}

				int p;
				for(p = Util.random.nextInt(9); vs[p] == 0; p = Util.random.nextInt(9)) {
				}

				if (j > vs[p]) {
					j = vs[p];
				}

				vs[p] -= j;
			}

			baby.setQizhi(vs[0]);
			baby.setNeili(vs[1]);
			baby.setZhili(vs[2]);
			baby.setNaili(vs[3]);
			baby.setMingqi(vs[4]);
			baby.setDaode(vs[5]);
			baby.setPanni(vs[6]);
			baby.setWanxing(vs[7]);
			baby.setXiaoxin(vs[8]);
			baby.setBabyage(baby.getBabyage() - 360);
			UpdaBaby(baby);
			if (FormsManagement.getframe(1).isVisible()) {
				TestChildJframe.getTestChildJframe().getTestChildJpanel().ShowBaby(baby);
			}

			ZhuFrame.getZhuJpanel().addPrompt2("孩子回到了一年前");
			goodstable.goodxh(1);
			GoodsMouslisten.gooduse(goodstable, 1);
		}
	}

	public static void babySkill(Baby baby, Goodstable goodstable) {
		String sendmes = Agreement.getAgreement().userbabyAgreement(goodstable.getRgid().toString() + "|" + baby.getBabyid());
		SendMessageUntil.toServer(sendmes);
	}

	public static void babySkillUP(Baby baby, Goodstable goodstable) {
	}

	public static void babyParts(Baby baby, Goodstable good2) {
		int type = (int)(good2.getType() - 54) / 2;
		if (type < 0) {
			type = 0;
		} else if (type > 3) {
			type = 3;
		}

		if (baby.getChildSex() == 0 && good2.getType() % 2 != 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("这是女孩子用的");
		} else if (baby.getChildSex() == 1 && good2.getType() % 2 == 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("这是男孩子用的");
		} else {
			Goodstable good1 = (Goodstable)GoodsListFromServerUntil.fushis.get(baby.ChangePart(good2.getRgid(), type));
			if (TestChildJframe.getTestChildJframe().getTestChildJpanel().ChangeParts(baby, good1, good2, type)) {
				UpdaBaby(baby);
			} else if (good1 == null) {
				baby.ChangePart(new BigDecimal(-1), type);
			} else {
				baby.ChangePart(good1.getRgid(), type);
			}

		}
	}

	public static void UpdaBaby(Baby baby) {
		String serverMes = null;

		try {
			serverMes = Agreement.getAgreement().updababy(GsonUtil.getGsonUtil().getgson().toJson(baby));
		} catch (Exception var3) {
			var3.printStackTrace();
		}

		SendMessageUntil.toServer(serverMes);
	}
}
